<template>
  <div class="breadcrumb-container" v-if="breadcrumbs.length > 1">
    <div class="breadcrumb-wrapper">
      <nav class="breadcrumb-nav">
        <ol class="breadcrumb-list">
          <li
            v-for="(breadcrumb, index) in breadcrumbs"
            :key="index"
            class="breadcrumb-item"
            :class="{ 'active': index === breadcrumbs.length - 1 }"
          >
            <router-link
              v-if="index < breadcrumbs.length - 1"
              :to="breadcrumb.path"
              class="breadcrumb-link"
            >
              <i v-if="breadcrumb.icon" :class="breadcrumb.icon" class="breadcrumb-icon"></i>
              {{ breadcrumb.name }}
            </router-link>
            <span v-else class="breadcrumb-current">
              <i v-if="breadcrumb.icon" :class="breadcrumb.icon" class="breadcrumb-icon"></i>
              {{ breadcrumb.name }}
            </span>
            <i
              v-if="index < breadcrumbs.length - 1"
              class="glyphicon glyphicon-chevron-right breadcrumb-separator"
            ></i>
          </li>
        </ol>
      </nav>
    </div>
  </div>
</template>

<script setup name="Breadcrumb">
import { computed } from 'vue'
import { useRoute } from 'vue-router'

const route = useRoute()

// 路由映射配置
const routeMap = {
  '/home': { name: '首页', icon: 'glyphicon glyphicon-home' },
  '/software': { name: '公司产品', icon: 'glyphicon glyphicon-th-large' },
  '/software/smartTown': { name: '创业者之家平台', icon: 'glyphicon glyphicon-briefcase' },
  '/software/bigData': { name: 'GuDB数据库引擎', icon: 'glyphicon glyphicon-hdd' },
  '/software/surpriseYard': { name: '箱野盲盒商城', icon: 'glyphicon glyphicon-gift' },
  '/service': { name: '相关服务', icon: 'glyphicon glyphicon-cog' },
  '/servicedetail': { name: '服务详情', icon: 'glyphicon glyphicon-info-sign' },
  '/newsinformation': { name: '新闻动态', icon: 'glyphicon glyphicon-list-alt' },
  '/news': { name: '新闻详情', icon: 'glyphicon glyphicon-file' },
  '/companyintroduction': { name: '公司介绍', icon: 'glyphicon glyphicon-info-sign' },
  '/jobchance': { name: '工作机会', icon: 'glyphicon glyphicon-user' },
  '/contactus': { name: '联系我们', icon: 'glyphicon glyphicon-envelope' }
}

// 生成面包屑导航
const breadcrumbs = computed(() => {
  const paths = []
  const currentPath = route.path

  // 总是添加首页
  paths.push({
    name: routeMap['/home'].name,
    path: '/home',
    icon: routeMap['/home'].icon
  })

  // 如果当前不是首页，添加当前页面
  if (currentPath !== '/home') {
    // 处理嵌套路由
    if (currentPath.startsWith('/software/')) {
      // 先添加软件产品父页面
      if (currentPath !== '/software') {
        paths.push({
          name: routeMap['/software'].name,
          path: '/software',
          icon: routeMap['/software'].icon
        })
      }
    } else if (currentPath.startsWith('/news/')) {
      // 先添加新闻动态父页面
      paths.push({
        name: routeMap['/newsinformation'].name,
        path: '/newsinformation',
        icon: routeMap['/newsinformation'].icon
      })
    }

    // 添加当前页面
    let currentRoute = routeMap[currentPath]

    // 处理动态路由
    if (!currentRoute && currentPath.startsWith('/news/')) {
      currentRoute = routeMap['/news']
    }

    if (currentRoute) {
      paths.push({
        name: currentRoute.name,
        path: currentPath,
        icon: currentRoute.icon
      })
    }
  }

  return paths
})
</script>

<style scoped>
/* 面包屑导航样式 - 苹果风格 */
.breadcrumb-container {
  background: rgba(245, 245, 247, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  padding: 16px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
}

.breadcrumb-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.breadcrumb-nav {
  display: flex;
  align-items: center;
}

.breadcrumb-list {
  display: flex;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 8px;
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.breadcrumb-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 400;
  color: #0071e3;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  background: transparent;
  border: 1px solid transparent;
}

.breadcrumb-link:hover {
  background: rgba(0, 113, 227, 0.08);
  border-color: rgba(0, 113, 227, 0.15);
  color: #0077ed;
  text-decoration: none;
  transform: translateY(-1px);
}

.breadcrumb-current {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #1d1d1f;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.breadcrumb-icon {
  font-size: 12px;
  opacity: 0.8;
}

.breadcrumb-separator {
  font-size: 10px;
  color: #86868b;
  margin: 0 4px;
  opacity: 0.6;
}

.breadcrumb-item.active .breadcrumb-current {
  background: rgba(0, 113, 227, 0.1);
  border-color: rgba(0, 113, 227, 0.2);
  color: #0071e3;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .breadcrumb-container {
    padding: 12px 0;
  }

  .breadcrumb-wrapper {
    padding: 0 16px;
  }

  .breadcrumb-list {
    gap: 4px;
  }

  .breadcrumb-link,
  .breadcrumb-current {
    padding: 6px 8px;
    font-size: 13px;
  }

  .breadcrumb-icon {
    font-size: 11px;
  }

  .breadcrumb-separator {
    font-size: 9px;
    margin: 0 2px;
  }
}

@media (max-width: 480px) {
  .breadcrumb-link,
  .breadcrumb-current {
    padding: 4px 6px;
    font-size: 12px;
  }

  .breadcrumb-icon {
    display: none;
  }

  .breadcrumb-list {
    gap: 2px;
  }
}

/* 动画效果 */
.breadcrumb-item {
  animation: fadeInSlide 0.3s ease-out;
}

@keyframes fadeInSlide {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* 暗色主题支持（可选） */
@media (prefers-color-scheme: dark) {
  .breadcrumb-container {
    background: rgba(28, 28, 30, 0.8);
    border-bottom-color: rgba(255, 255, 255, 0.1);
  }

  .breadcrumb-link {
    color: #0984ff;
  }

  .breadcrumb-link:hover {
    background: rgba(9, 132, 255, 0.15);
    border-color: rgba(9, 132, 255, 0.25);
    color: #40a9ff;
  }

  .breadcrumb-current {
    color: #f2f2f7;
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
  }

  .breadcrumb-item.active .breadcrumb-current {
    background: rgba(9, 132, 255, 0.2);
    border-color: rgba(9, 132, 255, 0.3);
    color: #0984ff;
  }

  .breadcrumb-separator {
    color: #8e8e93;
  }
}
</style>